using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQVW_KSLEIST
    {
        public DataRow Convert2QVW_KSLEIST(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQVW_KSLEIST(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["KDATE"] = " ".PadRight(0 ); 
         dwReturn["KYEAR"] = " ".PadRight(4 ); 
         dwReturn["KMONTH"] = " ".PadRight(2 ); 
         dwReturn["KDAY"] = " ".PadRight(2 ); 
         dwReturn["AUFTYP"] = " ".PadRight(1 ); 
         dwReturn["PKRS"] = " ".PadRight(2 ); 
         dwReturn["PLFD"] = " ".PadRight(6 ); 
         dwReturn["PPOS"] = " ".PadRight(3 ); 
         dwReturn["PFSTEP"] = " ".PadRight(3 ); 
         dwReturn["KOPERATION"] = " ".PadRight(15 ); 
         dwReturn["HRSTAFF"] = " ".PadRight(8 ); 
         dwReturn["KSHIFT"] = " ".PadRight(1 ); 
         dwReturn["KSLMZTV"] = " ".PadRight(0 ); 
         dwReturn["KSLMZTB"] = " ".PadRight(0 ); 
         dwReturn["PRECTIME"] = " ".PadRight(0 ); 
         dwReturn["PRCOST"] = " ".PadRight(0 ); 
         dwReturn["KSLMGMTR"] = " ".PadRight(0 ); 
         dwReturn["KSLMGKG"] = " ".PadRight(0 ); 
         dwReturn["KST"] = " ".PadRight(6 ); 
         dwReturn["MACHINENO"] = " ".PadRight(8 ); 
         dwReturn["KSLMPROG"] = " ".PadRight(8 ); 
         dwReturn["KSLMCODE"] = " ".PadRight(3 ); 
         dwReturn["KSLSEVARHNR"] = " ".PadRight(2 ); 
         dwReturn["KSLSEVARUNR"] = " ".PadRight(2 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQVW_KSLEIST(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQVW_KSLEIST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQVW_KSLEIST(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQVW_KSLEIST(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQVW_KSLEIST(dwLocal, ITXDBVERSION);
            }
            UpdateQVW_KSLEIST(dwLocal);
        }
        public void InsertQVW_KSLEIST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QVW_KSLEIST(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQVW_KSLEIST(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QVW_KSLEIST WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QVW_KSLEIST  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QVW_KSLEIST";
            Return = Result;
            return Return;
        }
        public void DeleteQVW_KSLEIST(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QVW_KSLEIST   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQVW_KSLEIST(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QVW_KSLEIST SET "
                    +"KDATE= :KDATE,"
                    +"KYEAR= :KYEAR,"
                    +"KMONTH= :KMONTH,"
                    +"KDAY= :KDAY,"
                    +"AUFTYP= :AUFTYP,"
                    +"PKRS= :PKRS,"
                    +"PLFD= :PLFD,"
                    +"PPOS= :PPOS,"
                    +"PFSTEP= :PFSTEP,"
                    +"KOPERATION= :KOPERATION,"
                    +"HRSTAFF= :HRSTAFF,"
                    +"KSHIFT= :KSHIFT,"
                    +"KSLMZTV= :KSLMZTV,"
                    +"KSLMZTB= :KSLMZTB,"
                    +"PRECTIME= :PRECTIME,"
                    +"PRCOST= :PRCOST,"
                    +"KSLMGMTR= :KSLMGMTR,"
                    +"KSLMGKG= :KSLMGKG,"
                    +"KST= :KST,"
                    +"MACHINENO= :MACHINENO,"
                    +"KSLMPROG= :KSLMPROG,"
                    +"KSLMCODE= :KSLMCODE,"
                    +"KSLSEVARHNR= :KSLSEVARHNR,"
                    +"KSLSEVARUNR= :KSLSEVARUNR,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("KDATE", OracleType.NVarChar).Value = dwData["KDATE"].ToString(); 
          or1.Parameters.Add("KYEAR", OracleType.NVarChar).Value = dwData["KYEAR"].ToString(); 
          or1.Parameters.Add("KMONTH", OracleType.NVarChar).Value = dwData["KMONTH"].ToString(); 
          or1.Parameters.Add("KDAY", OracleType.NVarChar).Value = dwData["KDAY"].ToString(); 
          or1.Parameters.Add("AUFTYP", OracleType.NVarChar).Value = dwData["AUFTYP"].ToString(); 
          or1.Parameters.Add("PKRS", OracleType.NVarChar).Value = dwData["PKRS"].ToString(); 
          or1.Parameters.Add("PLFD", OracleType.NVarChar).Value = dwData["PLFD"].ToString(); 
          or1.Parameters.Add("PPOS", OracleType.NVarChar).Value = dwData["PPOS"].ToString(); 
          or1.Parameters.Add("PFSTEP", OracleType.NVarChar).Value = dwData["PFSTEP"].ToString(); 
          or1.Parameters.Add("KOPERATION", OracleType.NVarChar).Value = dwData["KOPERATION"].ToString(); 
          or1.Parameters.Add("HRSTAFF", OracleType.NVarChar).Value = dwData["HRSTAFF"].ToString(); 
          or1.Parameters.Add("KSHIFT", OracleType.NVarChar).Value = dwData["KSHIFT"].ToString(); 
          or1.Parameters.Add("KSLMZTV", OracleType.NVarChar).Value = dwData["KSLMZTV"].ToString(); 
          or1.Parameters.Add("KSLMZTB", OracleType.NVarChar).Value = dwData["KSLMZTB"].ToString(); 
          or1.Parameters.Add("PRECTIME", OracleType.NVarChar).Value = dwData["PRECTIME"].ToString(); 
          or1.Parameters.Add("PRCOST", OracleType.NVarChar).Value = dwData["PRCOST"].ToString(); 
          or1.Parameters.Add("KSLMGMTR", OracleType.NVarChar).Value = dwData["KSLMGMTR"].ToString(); 
          or1.Parameters.Add("KSLMGKG", OracleType.NVarChar).Value = dwData["KSLMGKG"].ToString(); 
          or1.Parameters.Add("KST", OracleType.NVarChar).Value = dwData["KST"].ToString(); 
          or1.Parameters.Add("MACHINENO", OracleType.NVarChar).Value = dwData["MACHINENO"].ToString(); 
          or1.Parameters.Add("KSLMPROG", OracleType.NVarChar).Value = dwData["KSLMPROG"].ToString(); 
          or1.Parameters.Add("KSLMCODE", OracleType.NVarChar).Value = dwData["KSLMCODE"].ToString(); 
          or1.Parameters.Add("KSLSEVARHNR", OracleType.NVarChar).Value = dwData["KSLSEVARHNR"].ToString(); 
          or1.Parameters.Add("KSLSEVARUNR", OracleType.NVarChar).Value = dwData["KSLSEVARUNR"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
